import asyncio
import time

from playwright.async_api import async_playwright


async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=False)
        page = await browser.new_page()
        await page.goto("https://www.baidu.com/s?wd=%E8%BF%99%E9%A1%B9%E6%8A%80%E6%9C%AF%E6%80%BB%E4%B9%A6%E8%AE%B0%E5%BC%BA%E8%B0%83%E8%A6%81%E5%8A%A0%E5%BF%AB%E5%8F%91%E5%B1%95&sa=fyb_n_homepage&rsv_dl=fyb_n_homepage&from=super&cl=3&tn=baidutop10&fr=top1000&rsv_idx=2&hisfilter=1")
       # 滚动到元素可见
        await page.locator('//*[@id="page"]/div/a[10]/span').scroll_into_view_if_needed()
        time.sleep(2)
        await browser.close()

asyncio.run(main())
